Page({
  data: {
    babyList:[]
  },
  onLoad() {
    this.getList()
  },
  getList(){

    
    
    wx.request({
      url: getApp().globalData.apiBaseUrl + 'baby/findPage',
      data: {
        userId: 1
      },
      method: 'post',
      success: (res) => {
        if (res.data.code == 200) {
          this.setData({
            babyList:res.data.data.list
          })
        }
      }
    })
  },
  toInfo(e){
    wx.navigateTo({
      url: '/pages/baby-detail/index?id='+e.currentTarget.dataset.id,
    })
  },
  toDel(e){
    let that=this
    wx.showModal({
      title: '提示',
      content: '确定删除该宝宝吗？',
      success (res) {
        if (res.confirm) {
          wx.request({
            url: getApp().globalData.apiBaseUrl + 'baby/delete',
            data: {
              id: e.currentTarget.dataset.id
            },
            method: 'post',
            success: (res) => {
              if (res.data.code == 200) {
                that.getList()
              }
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  toAdd(e){
    wx.navigateTo({
      url: '/pages/add/index?id='+e.currentTarget.dataset.id,
    })
  }
});
